<?php

namespace Laoha\Blog\Models;

use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\App;
use App\Models\Cate;
//use App\Models\Traits\AppOrdered;
use App\Models\Traits\AppCate;
use App\Models\Traits\AppPos;
use App\Models\Traits\AppUser;
use App\Models\Traits\AppStatus;
use App\Models\Traits\AppAttach;
class LaohaBlog extends Model
{
	use SoftDeletes,AppCate,AppPos,AppUser,AppStatus,AppAttach; //AppOrdered,

	public $incrementing = false;

	public $app_name = 'laoha_blog';  //设置app_name 
	public $casts = ['images'=>'json'];  //设置字段格式 


	//批量赋值白名单，guarded为黑名单
	protected $fillable = [
        'user_id', 'cate_id', 'pos','status','group','updated_at'
    ];

	//protected $appends = ['desc'];

	public static function boot()
	{
		parent::boot();

		self::creating(function ($model) {     //创建时生成uuid
			$model->{$model->getKeyName()} = uuid();
		});


/*
        static::saving(function($model) {
			
            if(!empty($model->attributes['content'])){
				if( empty($model->original['content']) || $model->attributes['content']!=$model->original['content']){
					$model->attributes['desc'] = mb_substr(strip_tags($model->attributes['content']),0,100); //自动设置desc值
				}
			}
			//dd($model);
			if(empty($model->attributes['user_id']) && !empty(Auth::guard('admin')->user()->user_id)){
				$model->attributes['user_id'] = Auth::guard('admin')->user()->user_id;
			}
			return $model;
        });*/
	} 

	public function get_appends(){
		return $this->appends ?? [];
	}

}
